define(['app'], function(app) {
    'use strict';

    //实例化方法
    var factory = function (Http) {
		function get_data_get_afpy(result){
			if(false){
				result = '{"success":true,"msg":"","result":{"payment":[{"pay_id":"002","pay_name":"支付宝","logo":"img/guilin/afsrue/pay02.png","pay_kind":"1"},{"pay_id":"003","pay_name":"微信支付","logo":"img/guilin/afsrue/pay01.png","pay_kind":"1"},{"pay_id":"005","pay_name":"授信支付","logo":"img/guilin/afsrue/pay04.png","pay_kind":"2"}]},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			}else
			return result;
		}
		
        //返回信息
        return {
        	get_afpay: function(order_id,platform,callback){
        		Http.post({
        			method:'payment.mobilepay.detail',
        			order_id:order_id,
        			platform:platform
        		},function(result){
        			if(callback)
        			callback(get_data_get_afpy(result).result);
        		},function(e){
        			
        		},function(){
        			
        		})
        	},
        	go_pay:function(order_id,pay_app_id,image_id,bank_id,password,callback){
        		//此处微信公众号调用
        		var openid = localStorage.getItem("wx_openid");
        		Http.post({
        			method:'payment.mobilepay.createpayment',
        			order_id:order_id,
        			pay_app_id:pay_app_id,
        			image_id:image_id,
        			bank_id:bank_id,
        			payPass:password,
        			openid:openid
        		},function(result){
        			if(callback)
        				callback(result);
        		})
        	},
        	after_pay:function(order_id,trade_no,callback){
        		Http.post({
        			method:'payment.mobilepay.payfinish',
        			order_id:order_id,
        			trade_no:trade_no
        		},function(result){
        			if(callback)
        			callback(result);
        		})
        	},
        	go_pay_more:function(order_id,pay_app_id,image_id,bank_id,password,callback){
        		//此处微信公众号调用
        		var openid = localStorage.getItem("wx_openid");
        		Http.post({
        			method:'payment.mobilepay.allcreatepayment',
        			order_ids:order_id,
        			pay_app_id:pay_app_id,
        			image_id:image_id,
        			bank_id:bank_id,
        			payPass:password,
        			openid:openid
        		},function(result){
        			if(callback)
        				callback(result);
        		})
        	}
            
        };
    }

    factory.$inject = ['Http'];
    return app.registerService("Afpay", factory);
});